package org.dromara.web.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.domain.model.LoginUser;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.handler.InjectionMetaObjectHandler;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BaseController;
import org.dromara.web.domain.TPay;
import org.dromara.web.domain.bo.TPayBo;
import org.dromara.web.domain.vo.TPayVo;
import org.dromara.web.service.TPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Validated
@RestController
@SaIgnore
@RequiredArgsConstructor
@RequestMapping("/pay")
@Slf4j
public class TPayController extends BaseController {

    private final TPayService tPayService;



    /**
     * 获取支付信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("pay:pay:query")
    @GetMapping("/{id}")
    public R<TPayVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(tPayService.queryById(id));
    }

    /**
     * 查询支付信息列表
     */
    @SaCheckPermission("pay:pay:list")
    @GetMapping("/list")
    public TableDataInfo<TPayVo> list(@ModelAttribute TPayBo bo, @ModelAttribute PageQuery pageQuery) {
        return tPayService.queryPageList(bo, pageQuery);
    }


    /**
     * 修改支付信息
     */
    @SaCheckPermission("pay:pay:edit")
    @Log(title = "支付信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TPayBo bo) {
        return toAjax(tPayService.updateByBo(bo));
    }

}
